//
//  ShoppingView.swift
//  DollBuy
//
//  Created by 郑东喜 on 2016/12/2.
//  Copyright © 2016年 郑东喜. All rights reserved.
//

import UIKit

class ShoppingView: UIView {

    override init(frame: CGRect) {
        super.init(frame: frame)
        
//        self.backgroundColor = UIColor.gray
        setUI()
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }

}

// MARK:- 初始化视图
extension ShoppingView {
    func setUI() -> Void {
        

        //购物车文字
        let titleLabel = UILabel()
        titleLabel.frame = CGRect(x: 0, y: SH / 2 - 10, width: SW, height: 20)
        titleLabel.text = "您的购物车空如也添加点东西吧~"
        titleLabel.textAlignment = NSTextAlignment.center
        titleLabel.font = UIFont.systemFont(ofSize: 13)
        titleLabel.textColor = UIColor.gray
        self.addSubview(titleLabel)
        
        //购物车图片
        let shoppImg = UIImageView()
        //        #imageLiteral(resourceName: "ShoppingCar")
        shoppImg.frame = CGRect(x: SW / 2 - 50, y: SH / 2 - titleLabel.Height / 2 - 10 - 100, width: 100, height: 100)
        shoppImg.image = UIImage.init(named: "ShoppingCar")
        self.addSubview(shoppImg)
        
        
        //按钮
        let btn = UIButton()
        btn.center = self.center
        
        btn.frame = CGRect(x: SW / 2 - (width: UIScreen.main.bounds.width * 0.3) / 2 , y: titleLabel.BottomY + 10, width: UIScreen.main.bounds.width * 0.3, height: 35)
        btn.backgroundColor = UIColor.orange
        btn.layer.cornerRadius = 8
        self.addSubview(btn)
        btn.setTitle("马上云购", for: .normal)
        btn.setTitle("马上云购", for: .highlighted)
        btn.titleLabel?.font = UIFont.systemFont(ofSize: 13)
        btn.addTarget(self, action: #selector(ShoppingView.jumpToMain), for: .touchUpInside)
    }
}

// MARK:- 单机事件
extension ShoppingView {
    func jumpToMain() -> Void {
        print("眺望到主界面")
        
        let mainVC = MainViewController()
        
        mainVC.selectedIndex = 0
        
        UIApplication.shared.keyWindow?.rootViewController = mainVC
        
    }
}
